package com.ai.imagetext.controller;

import com.ai.imagetext.service.FileUploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class TestController {

    private final FileUploadService fileUploadService;

    @GetMapping("/health")
    public Map<String, Object> health() {
        Map<String, Object> response = new HashMap<>();
        response.put("status", "ok");
        response.put("message", "AI图文管理助手后端服务运行正常");
        response.put("timestamp", System.currentTimeMillis());
        
        // 检查上传目录
        File uploadDir = new File("./uploads/");
        response.put("uploadDirExists", uploadDir.exists());
        response.put("uploadDirPath", uploadDir.getAbsolutePath());
        
        // 获取上传统计
        try {
            FileUploadService.UploadStatistics stats = fileUploadService.getUploadStatistics();
            response.put("uploadStats", stats);
        } catch (Exception e) {
            response.put("uploadStatsError", e.getMessage());
        }
        
        return response;
    }
}